/*
 * UAE - The Un*x Amiga Emulator
 *
 * Debugger
 *
 * (c) 1995 Bernd Schmidt
 *
 */

#pragma once

#ifdef DEBUGGER

    #define MAX_HIST 500
    #define MAX_LINEWIDTH 100

extern int debugging;
extern int exception_debugging;
extern int debug_copper;
extern int debug_dma;
extern int debug_sprite_mask;
extern int debug_bpl_mask, debug_bpl_mask_one;
extern int debugger_active;
extern int debug_illegal;
extern ulong64 debug_illegal_mask;

extern void debug();
extern void debugger_change(int mode);
extern void activate_debugger();
extern void deactivate_debugger();
extern int notinrom();
extern const TCHAR* debuginfo(int);
extern void record_copper(uae_ptr addr, int hpos, int vpos);
extern void record_copper_reset();
extern int mmu_init(int, uae_ptr, uae_ptr);
extern void mmu_do_hit();
extern void dump_aga_custom();
extern void memory_map_dump();
extern void debug_help();
extern uae_ptr dumpmem2(uae_ptr addr, TCHAR* out, int osize);
extern void update_debug_info();
extern int instruction_breakpoint(TCHAR** c);
extern int debug_bankchange(int);
extern void log_dma_record();
extern void debug_parser(const TCHAR* cmd, TCHAR* out, uint outsize);

    #define BREAKPOINT_TOTAL 20
struct breakpoint_node
{
    uae_ptr addr;
    int enabled;
};
extern struct breakpoint_node bpnodes[BREAKPOINT_TOTAL];

    #define MEMWATCH_TOTAL 20
struct memwatch_node
{
    uae_ptr addr;
    int size;
    int rwi;
    uint val, val_mask;
    int val_size, val_enabled;
    int mustchange;
    uint modval;
    int modval_written;
    int frozen;
    uae_ptr pc;
};
extern struct memwatch_node mwnodes[MEMWATCH_TOTAL];

extern void memwatch_dump2(TCHAR* buf, int bufsize, int num);

ushort debug_wgetpeekdma(uae_ptr addr, uint v);
ushort debug_wputpeekdma(uae_ptr addr, uint v);
void debug_lgetpeek(uae_ptr addr, uint v);
void debug_wgetpeek(uae_ptr addr, uint v);
void debug_bgetpeek(uae_ptr addr, uint v);
void debug_bputpeek(uae_ptr addr, uint v);
void debug_wputpeek(uae_ptr addr, uint v);
void debug_lputpeek(uae_ptr addr, uint v);

enum debugtest_item { DEBUGTEST_BLITTER, DEBUGTEST_KEYBOARD, DEBUGTEST_FLOPPY, DEBUGTEST_MAX };
void debugtest(enum debugtest_item, const TCHAR*, ...);

struct dma_rec
{
    ushort reg;
    ushort dat;
    uint addr;
    ushort evt;
    int type;
};

    #define DMA_EVENT_BLITIRQ 1
    #define DMA_EVENT_BLITNASTY 2
    #define DMA_EVENT_BLITFINISHED 4
    #define DMA_EVENT_BPLFETCHUPDATE 8
    #define DMA_EVENT_COPPERWAKE 16
    #define DMA_EVENT_CPUIRQ 32
    #define DMA_EVENT_INTREQ 64

    #define DMARECORD_REFRESH 1
    #define DMARECORD_CPU 2
    #define DMARECORD_COPPER 3
    #define DMARECORD_AUDIO 4
    #define DMARECORD_BLITTER 5
    #define DMARECORD_BLITTER_LINE 6
    #define DMARECORD_BITPLANE 7
    #define DMARECORD_SPRITE 8
    #define DMARECORD_DISK 9
    #define DMARECORD_MAX 10

extern struct dma_rec* record_dma(ushort reg, ushort dat, uint addr, int hpos, int vpos, int type);
extern void record_dma_reset();
extern void record_dma_event(int evt, int hpos, int vpos);
extern void debug_draw_cycles(byte* buf, int bpp, int line, int width, int height, uint* xredcolors, uint* xgreencolors, uint* xbluescolors);

#else

static __forceinline void activate_debugger()
{
}

#endif

namespace Debugger
{
    extern bool start_debugger;
}